using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;


namespace GameWP
{
    public class UpgradeGeneralComponent : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Game _game;
        private SpriteBatch _spriteBatch;
        private SpriteFont _menuFont, _textFont;
        private Vector2 touchPosition, pretouchPosition;
        public List<Button> _listItemMenu;
        public Button _levelLuffy, _hpLuffy, _manaLuffy, _damLuffy, _balanceLuffy;
        public List<Button> ListItemMenu
        {
            get { return _listItemMenu; }
            set { _listItemMenu = value; }
        }


        //Initilation
        public UpgradeGeneralComponent(Game game, SpriteFont menuFont, SpriteFont textFont, SpriteBatch spriteBatch)
            : base(game)
        {
            _game = game;
            _menuFont = menuFont;
            _textFont = textFont;
            _spriteBatch = spriteBatch;

            //Init list menu item
            ListItemMenu = new List<Button>();
            ListItemMenu.Add(new Button("Back to Menu", _textFont, new Vector2(560, 440), Color.Red));
            ListItemMenu.Add(new Button("Next", _textFont, new Vector2(20, 440), Color.Red));
            //Choose component noi bo cua UpdateScreen
            ListItemMenu.Add(new Button("Luffy", _textFont, new Vector2(530, 170), Color.Green));
            ListItemMenu.Add(new Button("Skill", _textFont, new Vector2(530, 240), Color.Red));
            ListItemMenu.Add(new Button("Member", _textFont, new Vector2(530, 310), Color.Red));

            //Init intinsict Button
            _levelLuffy = new Button("", _textFont, new Vector2(50, 140), Color.Red) { HaveAnimation = false };
            _hpLuffy = new Button("", _textFont, new Vector2(160, 60), Color.White) { HaveAnimation = false };
            _manaLuffy = new Button("", _textFont, new Vector2(160, 100), Color.White) { HaveAnimation = false };
            _damLuffy = new Button("", _textFont, new Vector2(160, 140), Color.White) { HaveAnimation = false };
            _balanceLuffy = new Button("", _menuFont, new Vector2(430, 75), Color.Yellow) { HaveAnimation = false };
        }

        public override void Initialize()
        {
            // TODO: Add your initialization code here
                base.Initialize();
        }

        public void SetColorTabActive(int index)
        {
            ListItemMenu[index].ColorText = Color.Green;
            for (int i = 2; i < 5; i++)
                if (i != index) ListItemMenu[i].ColorText = Color.Red;
        }

        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here    
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                _game.Exit();
            //Key input
            //Key input
            TouchCollection touchCollection = TouchPanel.GetState();
            touchPosition = Vector2.Zero;
            if (touchCollection.Count > 0)
            {
                touchPosition = touchCollection[0].Position;
                if (touchPosition == pretouchPosition) return;
                pretouchPosition = touchPosition;
            }

            for (int i = 0; i < ListItemMenu.Count; i++)
                        ListItemMenu[i].ButtonIsTouched(touchPosition, i);            
            _levelLuffy.Text = "Lv " + ManagerGame.luffy.Level.ToString();
            _hpLuffy.Text =   "Hp    : " + ManagerGame.luffy.Hp.ToString();
            _manaLuffy.Text = "Mana : " + ManagerGame.luffy.Mana.ToString();
            _damLuffy.Text =  "Dam  : " + ManagerGame.luffy.Damage.ToString();
            _balanceLuffy.Text = ManagerGame.luffy.Balance.ToString();
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            for (int i = 0; i < ListItemMenu.Count; i++)
                ListItemMenu[i].Draw(_spriteBatch, gameTime);
            _levelLuffy.Draw(_spriteBatch, gameTime);
            _hpLuffy.Draw(_spriteBatch, gameTime);
            _manaLuffy.Draw(_spriteBatch, gameTime);
            _damLuffy.Draw(_spriteBatch, gameTime);
            _balanceLuffy.Draw(_spriteBatch, gameTime);
        }
    }
}
